<template>
	<view class="cake-item" :class="{'m-r-0':idx%2!=0}">
		<image :src="gdata.img" mode=""></image>
		<view class="flex justify-between align-center">
			<view class="">
				<view class="margin-top-xs text-bold text-sm">
					{{gdata.name}}
				</view>
				<view class="text-sm margin-tb-xs">
					{{gdata.french}}
				</view>
			</view>
			<view @click="handleModalShow" class="cart-btn margin-right-sm">
				<text class="iconfont icon-gouwuche"></text>
			</view>
		</view>
		<text class="text-price">{{gdata.price}}</text>
	</view>
</template>

<script>
	
	export default {
		name:"cake-item",
		props: {
			gdata: {
				type: Object,
				required:true
			},
			idx:Number 
		},
		data() {
			return {
				
			};
		},
		created(){ //公共组件中使用这个生命周期
			console.log('公共组件的created');
		},
		methods: {
			handleModalShow() {
				this.$store.commit('cart/modalMut',true)
				this.$store.commit('cart/modalDataMut',{
					goodObj:this.gdata,
					editIdx:-1
				})
			}
		},
	}
</script>

<style lang="scss">
.cake-item{
	width: 350upx;
	// background-color: orange;
	margin-right: 10upx;
	margin-bottom: 10upx;
	&:nth-of-type(2n){
		margin-right: 0;
	}
	&.m-r-0{
		margin-right: 0;
	}
	image{
		height: 350upx;
		width: 100%;
	}
	.cart-btn{
		width: 50upx;
		height: 50upx;
		border-radius: 50%;
		background-color: #FFE32A;
		text-align: center;
		line-height: 50upx;
	}
}
</style>